package january.test_1_26;

import java.util.Scanner;

public class main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String stA = scanner.nextLine();
        String stB = scanner.nextLine();
        int[] hash = new int[200];
        for(int i = 0; i < stA.length(); i++) {
            hash[stA.charAt(i)] ++;
        }
        for(int i = 0; i < stB.length(); i++) {
            hash[stB.charAt(i)] ++;
        }
        int tmp = 0;
        for(int i = 0; i < hash.length; i++) {
            if(hash[i] > 2) {
                tmp++;
            }
        }
        int count = 1;
        for(int i = tmp; i > 1;i--) {
            count = tmp * count;
        }
        System.out.println(count);
    }
}
